<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <link href="/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <!--<link href="/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">-->
    <link href="/css/plugins/nouslider/nouislider.css" rel="stylesheet">
    <link href="/css/plugins/nouslider/nouislider.pips.css" rel="stylesheet">
    <link href="/css/plugins/nouslider/nouislider.tooltips.css" rel="stylesheet">
    <style>
        .button-normal {
            background-color: #FFFFFF;
            border-color: #1ab394 !important;
            /*boder: 1px;*/
            color: #1ab394;
        }

        .button-done {
            background-color: #8a9bab;
            border-color: #8a9bab !important;
            /*boder: 1px;*/
            color: white;
        }

        .button-disabled {
            background-color: #cccccc;
            border-color: #cccccc !important;
            color: white;
        }

        .dropdown-menu {
            z-index: 3000 !important;
        }

        #one-week-schedule {
            table-layout: fixed;
        }

        #one-week-schedule td {
            text-align: center;
            vertical-align: middle;
            word-break: break-all;
        }

        #one-week-schedule td div.alt ,
        #one-week-schedule td.alt {
            position: relative;
        }

        #one-week-schedule td div.alt:hover {
            z-index: 2;
        }

        #one-week-schedule td div.alt div.training,
        #one-week-schedule td.alt  div.vacation-edit-div {
            display: none;
            z-index: 10;
        }

        #one-week-schedule td div.alt:hover div.training,
        #one-week-schedule td.alt:hover div.vacation-edit-div {
            position: absolute;
            display: block;
            float: left;
            top: -40px;
            left: 80px;
            border: 1px solid #c2c2c2;
            z-index: 10;
            color: black;
            background-color: white;
            opacity: 0.85;
            font-size: 12px;
        }

        .patient-div, .vacation-edit-div {
            text-align: center;
            height: 30px;
            /*width:30%;*/
            /*font-size: 14px;*/
            display: inline-block;
        }

        .td-not-finish {
            /*background-color: #1ab394;*/
            width: 15px;
            height: 15px;
        }

        .td-finish {
            /*background-color: #8a9bab;*/
            width: 15px;
            height: 15px;
        }

        .td-gauge {
            /*background-color: #8a9bab;*/
            width: 14px;
            height: 15px;
        }

        .td-training {
            width: 8px;
            height: 18px;
            /*background-color: #cccccc;*/
        }

        .small-rectangle {
            /*width: 15px;*/
            /*height: 15px;*/
            /*display: inline-block;*/
            vertical-align: middle;
            border: none;
        }

        .small-rectangle-text {
            margin-left: 3px;
            vertical-align: middle;
        }

        #one-week-schedule {
            border-collapse: separate !important;
            cellpadding: 0 !important;
            cellspacing: 0 !important;
            /*border-collapse:separate !important;*/
            /*border-left:1px solid #e7e7e7 !important;*/
            /*border-top:1px solid #e7e7e7 !important;*/
        }

        #one-week-schedule th, #one-week-schedule td {
            /*background-color: white !important;*/
            /*border-right:1px solid #e7e7e7 !important;*/
            /*border-bottom:1px solid #e7e7e7 !important;*/
            border: 1px solid rgb(245, 245, 245);
        }

        #one-week-schedule td {
            padding: 0px !important;
        }

        #one-week-schedule tbody tr:nth-child(n + 2) td {
            height: 55px !important;
        }

        .finish-img {
            background: url("/img/icon/chat.png") no-repeat 4px 5px;
        }

        .today-border {
            border: 1px solid #1ab394 !important;
        }

        .noUi-tooltip {
            line-height: 120%;
            padding: 0;
        }
        .ui-jqgrid-hdiv, .ui-jqgrid-hbox, .ui-jqgrid-htable, .ui-jqgrid-bdiv, .ui-jqgrid-btable {
            width: 100% !important;
            padding: 0 !important;
            margin: 0 !important;
        }
    </style>
</head>
<body>

<div class="row">
    <div class="infont col-sm-12  m-b" style="text-align: right"
         onclick="loadTitle('schedule/personal_schedule_title.html')"><a style="cursor:pointer;margin-right: 20px;"><i
            class="fa fa-area-chart"></i>一览表</a></div>
    <div class="col-sm-12">
        <div class="col-sm-12">
            <table cellpadding="0" cellspacing="0" class="table table-bordered" id="one-week-schedule">
                <thead>
                <tr style="height: 0">
                    <!--<td width="4%" class="no-padding"></td>-->
                    <td width="12.5%" class="no-padding"></td>
                    <td width="12.5%" class="no-padding"></td>
                    <td width="12.5%" class="no-padding"></td>
                    <td width="12.5%" class="no-padding"></td>
                    <td width="12.5%" class="no-padding"></td>
                    <td width="12.5%" class="no-padding"></td>
                    <td width="12.5%" class="no-padding"></td>
                    <td width="12.5%" class="no-padding"></td>
                </tr>
                <tr>
                    <th colspan="8" style="text-align: center;vertical-align: middle;">
                        <span onclick="lastWeek()" style="color: #0d8ddb;cursor: pointer;font-size: 14px">上一周</span>
                    <span id="week-periods-date"
                          style="padding-left: 20px;padding-right: 20px;">2016/08/01~2016/08/07</span>
                        <span onclick="nextWeek()" style="color: #0d8ddb;cursor: pointer;font-size: 14px">下一周</span>
                    </th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <!--<td rowspan="7" style="text-align: center;vertical-align: middle;">上午</td>-->
                    <td>时间</td>
                    <td id="td-1"><span>周一</span><br/><span id="week-1"></span></td>
                    <td id="td-2"><span>周二</span><br/><span id="week-2"></span></td>
                    <td id="td-3"><span>周三</span><br/><span id="week-3"></span></td>
                    <td id="td-4"><span>周四</span><br/><span id="week-4"></span></td>
                    <td id="td-5"><span>周五</span><br/><span id="week-5"></span></td>
                    <td id="td-6"><span>周六</span><br/><span id="week-6"></span></td>
                    <td id="td-7"><span>周日</span><br/><span id="week-7"></span></td>
                </tr>
                <tr id="morning-2">
                    <td id="time-block-1">08:00~08:30</td>
                    <td id="MON-1"></td>
                    <td id="TUE-1"></td>
                    <td id="WED-1"></td>
                    <td id="THU-1"></td>
                    <td id="FRI-1"></td>
                    <td id="SAT-1"></td>
                    <td id="SUN-1"></td>
                </tr>
                <tr id="morning-3">
                    <td id="time-block-2">08:35~09:05</td>
                    <td id="MON-2"></td>
                    <td id="TUE-2"></td>
                    <td id="WED-2"></td>
                    <td id="THU-2"></td>
                    <td id="FRI-2"></td>
                    <td id="SAT-2"></td>
                    <td id="SUN-2"></td>
                </tr>
                <tr id="morning-4">
                    <td id="time-block-3">09:10~09:40</td>
                    <td id="MON-3"></td>
                    <td id="TUE-3"></td>
                    <td id="WED-3"></td>
                    <td id="THU-3"></td>
                    <td id="FRI-3"></td>
                    <td id="SAT-3"></td>
                    <td id="SUN-3"></td>
                </tr>
                <tr id="morning-5">
                    <td id="time-block-4">09:45~10:15</td>
                    <td id="MON-4"></td>
                    <td id="TUE-4"></td>
                    <td id="WED-4"></td>
                    <td id="THU-4"></td>
                    <td id="FRI-4"></td>
                    <td id="SAT-4"></td>
                    <td id="SUN-4"></td>
                </tr>
                </tr>
                <tr id="morning-6">
                    <td id="time-block-5">10:20~10:50</td>
                    <td id="MON-5"></td>
                    <td id="TUE-5"></td>
                    <td id="WED-5"></td>
                    <td id="THU-5"></td>
                    <td id="FRI-5"></td>
                    <td id="SAT-5"></td>
                    <td id="SUN-5"></td>
                </tr>
                <tr id="morning-7">
                    <td id="time-block-6">10:55~11:25</td>
                    <td id="MON-6"></td>
                    <td id="TUE-6"></td>
                    <td id="WED-6"></td>
                    <td id="THU-6"></td>
                    <td id="FRI-6"></td>
                    <td id="SAT-6"></td>
                    <td id="SUN-6"></td>
                </tr>
                <tr id="afternoon-1">
                    <!--<td rowspan="7" style="text-align: center;vertical-align: middle;" width="4%">下午</td>-->
                    <td id="time-block-7">13:00~13:30</td>
                    <td id="MON-7"></td>
                    <td id="TUE-7"></td>
                    <td id="WED-7"></td>
                    <td id="THU-7"></td>
                    <td id="FRI-7"></td>
                    <td id="SAT-7"></td>
                    <td id="SUN-7"></td>
                </tr>
                <tr id="afternoon-2">
                    <td id="time-block-8">13:35~14:05</td>
                    <td id="MON-8"></td>
                    <td id="TUE-8"></td>
                    <td id="WED-8"></td>
                    <td id="THU-8"></td>
                    <td id="FRI-8"></td>
                    <td id="SAT-8"></td>
                    <td id="SUN-8"></td>
                </tr>
                <tr id="afternoon-3">
                    <td id="time-block-9">14:10~14:40</td>
                    <td id="MON-9"></td>
                    <td id="TUE-9"></td>
                    <td id="WED-9"></td>
                    <td id="THU-9"></td>
                    <td id="FRI-9"></td>
                    <td id="SAT-9"></td>
                    <td id="SUN-9"></td>
                </tr>
                <tr id="afternoon-4">
                    <td id="time-block-10">14:45~15:15</td>
                    <td id="MON-10"></td>
                    <td id="TUE-10"></td>
                    <td id="WED-10"></td>
                    <td id="THU-10"></td>
                    <td id="FRI-10"></td>
                    <td id="SAT-10"></td>
                    <td id="SUN-10"></td>
                </tr>
                <tr id="afternoon-5">
                    <td id="time-block-11">15:20~15:50</td>
                    <td id="MON-11"></td>
                    <td id="TUE-11"></td>
                    <td id="WED-11"></td>
                    <td id="THU-11"></td>
                    <td id="FRI-11"></td>
                    <td id="SAT-11"></td>
                    <td id="SUN-11"></td>
                </tr>
                <tr id="afternoon-6">
                    <td id="time-block-12">15:55~16:25</td>
                    <td id="MON-12"></td>
                    <td id="TUE-12"></td>
                    <td id="WED-12"></td>
                    <td id="THU-12"></td>
                    <td id="FRI-12"></td>
                    <td id="SAT-12"></td>
                    <td id="SUN-12"></td>
                </tr>
                <tr id="afternoon-7">
                    <td id="time-block-13">16:30~17:00</td>
                    <td id="MON-13"></td>
                    <td id="TUE-13"></td>
                    <td id="WED-13"></td>
                    <td id="THU-13"></td>
                    <td id="FRI-13"></td>
                    <td id="SAT-13"></td>
                    <td id="SUN-13"></td>
                </tr>
                </tbody>
            </table>
            <div class="row">
                <div class="col-sm-3"></div>

                <div class="col-sm-3" style="text-align: center;"><i class="fa fa-star-o"></i><span
                        class="small-rectangle-text">已取消训练</span></div>
                <div class="col-sm-3" style="text-align: center;"><i class="fa fa-star"
                                                                     style="color: #1ab394;"></i><span
                        class="small-rectangle-text">已完成训练</span></div>

                <!--<div class="col-sm-3"></div>-->
                <!--&lt;!&ndash;<div class="col-sm-3" style="text-align: center;"><img class="small-rectangle td-gauge" src="/img/schedule/schedule-gauge.png"><span class="small-rectangle-text">评估</span></div>&ndash;&gt;-->
                <!--&lt;!&ndash;<div class="col-sm-3" style="text-align: center;"><i class="fa fa-user-md"></i><span class="small-rectangle-text">训练</span></div>&ndash;&gt;-->
            </div>
            <div class="row" style="margin-top: 10px;">
                <div class="col-sm-9" style="">提示：每节课30分钟，间隔5分钟</div>
                <div class="col-sm-3" style="">
                    <button class="btn btn-w-m btn-primary inline-block" style="width: 102px;float: right;"
                            onclick="$('#modal-add-vacation-div').modal('show');buildAddVacationDiv();">
                        标记休假
                    </button>
                </div>
            </div>
        </div>

        <div class="col-sm-12" style="margin-top: 30px;">
            <h4>康复训练患者表</h4>

            <div class="row" style="padding: 5px 0;">
                <div class="col-sm-4">
                    <div class="input-group" style="padding: 0">
                        <input type="text" class="form-control" id="search-key" placeholder="患者编号 | 姓名">
                    <span class="input-group-btn">
                        <button type="button" class="btn btn-primary" onclick="search();">搜索</button>
                    </span>
                    </div>
                </div>
                <div class="col-sm-3 col-sm-offset-5" style="">
                    <select onchange="filterPatient(1)" class="form-control m-b"
                            id="patient-select" name="patient-select">
                        <option value="1">全部患者</option>
                        <option value="2">未安排患者</option>
                        <option value="3">已经安排患者</option>
                    </select>
                </div>
            </div>
            <div class="jqGrid_wrapper" id="my-patient-list" style="text-align: center;width: 100%;">
                <div id="scheduling-div" style="text-align: center;width: 100%;">
                    <table id="my-patient" style="text-align: center;width: 100%;"></table>
                </div>

                <div id="no-records">没有查询记录！</div>
                <div class="pagination" id="pagination">
                    <a class="first" id="first-btn-3" data-action="first"><i class="icon-double-angle-left"></i></a>
                					<a class="previous" id="previous-btn-3" data-action="previous"><i class="icon-angle-left"></i></a>
                					<input id="page-num-3" type="text" onkeydown="designatedPage(event, 2)"/>
               						<a class="next" id="next-btn-3" data-action="next"><i class="icon-angle-right"></i></a>
                					<a class="last" id="last_btn_3" data-action="last"><i class="icon-double-angle-right"></i></a>
                </div>
            </div>
        </div>
    </div>
    <div id="modal-schedule-div" class="row modal fade" aria-hidden="true">
        <div class="col-sm-12">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body" style="text-align: center;clear:both;border: 1px solid black;">
                        <div class="ibox">
                            <!--<div class="ibox-title">-->
                            <h5 style="text-align: center;clear:both;font-size: 16px;font-weight: bold;">选择时间</h5>
                            <!--</div>-->
                            <div class="ibox-content" style="border: none;">
                                <div class="form-group" id="data">
                                    <div class="m-b">
                                        <div class="input-group date">
                                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                            <input type="text" class="form-control" value="" id="date-input"
                                                   readonly="readonly" style="background: white">
                                        </div>
                                    </div>
                                    <div style="text-align: center;">
                                        <div id="time-block-button" style="min-height: 200px;">
                                        </div>
                                    </div>

                                    <div class="m-b" id="weeks-selector">
                                        <label class="m-b-lg">连续排课(周数)</label>
                                        <div id="basic_slider"></div>
                                    </div>

                                    <div class="">
                                        <div class="col-sm-6">
                                            <button data-dismiss="modal"
                                                    class="btn btn-white inline-block element-center"
                                                    style="width: 102px;">
                                                取消
                                            </button>
                                        </div>
                                        <div class="col-sm-6">
                                            <button onclick="submit()"
                                                    class="btn btn-w-m btn-primary inline-block element-center"
                                                    style="width: 102px;">
                                                确定
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>


                    </div>


                </div>
            </div>
        </div>
    </div>

    <div id="modal-choose-patient-div" class="row modal fade" aria-hidden="true">
        <div class="col-sm-12">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body" style="text-align: center;clear:both;border: 1px solid black;">
                        <div class="ibox" style="margin: 0">
                            <!--<div class="ibox-title">-->
                            <!--<h5 style="text-align: center;clear:both;font-size: 16px;font-weight: bold;">选择患者</h5>-->
                            <!--</div>-->
                            <div class="ibox-content" style="border: none;">
                                <h5 style="text-align: center;clear:both;font-size: 16px;font-weight: bold;margin-bottom: 25px">
                                    选择患者</h5>

                                <div class="form-group" id="data-patient">
                                    <div style="text-align: center;height: 30px;font-size: 14px;">
                                        <div class="col-sm-2" style="line-height: 30px;"></div>
                                        <div class="col-sm-7" style="text-align: center;vertical-align: middle;">
                                            <select class="form-control m-b" id="patient-choose" name="patient-choose"
                                                    onchange="changePatient('patient-choose')">
                                                <option value="0">请选择患者</option>
                                            </select>
                                        </div>
                                        <div class="col-sm-3" style="line-height: 30px;">
                                            <input type="checkbox" class="i-checks" onchange="filterPatient(2)"
                                                   id="patient-checkbox">未安排患者
                                        </div>
                                    </div>

                                    <div class="row" style="margin-top: 30px;">
                                        <div class="col-sm-6">
                                            <button data-dismiss="modal"
                                                    class="btn btn-w-m btn btn-white inline-block element-center"
                                                    style="width: 102px;">
                                                取消
                                            </button>
                                        </div>
                                        <div class="col-sm-6">
                                            <button onclick="submit2('patient-choose')"
                                                    class="btn btn-w-m btn-primary inline-block element-center"
                                                    style="width: 102px;">
                                                确定
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div id="modal-add-vacation-div" class="row modal fade" aria-hidden="true">
        <div class="col-sm-12">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body" style="text-align: center;clear:both;border: 1px solid black;">
                        <div class="ibox" style="margin: 0">
                            <!--<div class="ibox-title">-->
                            <!--<h5 style="text-align: center;clear:both;font-size: 16px;font-weight: bold;">选择患者</h5>-->
                            <!--</div>-->
                            <div class="ibox-content" style="border: none;">
                                <h5 style="text-align: center;clear:both;font-size: 16px;font-weight: bold;margin-bottom: 25px">
                                    添加休假</h5>

                                <div class="form-group" id="add-vacation">
                                    <div style="text-align: center;height: 30px;font-size: 14px;">
                                        <div class="col-sm-1" style="line-height: 30px;"></div>
                                        <div class="col-sm-11" style="text-align: center;vertical-align: middle;">
                                            <label class="col-sm-3 control-label">标题</label>

                                            <div class="col-sm-9 m-b">
                                                <input type="text" class="form-control" id="vacation-remark"
                                                       maxlength="15">
                                            </div>
                                        </div>
                                    </div>

                                    <div style="text-align: center;height: 30px;font-size: 14px;">
                                        <div class="col-sm-1" style="line-height: 30px;"></div>
                                        <div class="col-sm-11" style="line-height: 30px;">
                                            <label class="col-sm-3 control-label">类型</label>

                                            <div class="col-sm-9 m-b" style="text-align: left;">
                                                <input type="checkbox" class="i-checks" id="vacation-type"> 全天
                                            </div>
                                        </div>
                                    </div>

                                    <div style="text-align: center;height: 30px;font-size: 14px;">
                                        <div class="col-sm-1" style="line-height: 30px;"></div>
                                        <div class="col-sm-11" style="line-height: 30px;">
                                            <label class="col-sm-3 control-label">日期
                                            </label>

                                            <div class="col-sm-9 m-b-lg">
                                                <input type="text" class="form-control" id="vacation-date" readonly
                                                       style="background: white">
                                            </div>
                                        </div>
                                    </div>

                                    <div style="text-align: center;height: 30px;font-size: 14px;">
                                        <div class="col-sm-1" style="line-height: 30px;"></div>
                                        <div class="col-sm-11" style="line-height: 30px;">
                                            <label class="col-sm-3 control-label">时间</label>

                                            <div class="col-sm-9 m-b">
                                                <div id="vacation-time-slider"></div>
                                            </div>
                                        </div>
                                    </div>

                                    <div style="text-align: center;height: 30px;font-size: 14px;">
                                        <div class="col-sm-1" style="line-height: 30px;"></div>
                                        <div class="col-sm-11" style="line-height: 30px;">
                                            <label class="col-sm-3 control-label">重复
                                            </label>

                                            <div class="col-sm-9 m-b">
                                                <select class="form-control m-b" id="vacation-repeat-choose">
                                                    <option value="0">不重复</option>
                                                    <option value="1">每周</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="row" style="margin-top: 30px;">
                                        <div class="col-sm-6">
                                            <button data-dismiss="modal"
                                                    onclick="$('#modal-add-vacation-div').modal('hide');"
                                                    class="btn btn-w-m btn btn-white inline-block element-center"
                                                    style="width: 102px;">
                                                取消
                                            </button>
                                        </div>
                                        <div class="col-sm-6">
                                            <button onclick="addVacation()" id="vacation-btn"
                                                    class="btn btn-w-m btn-primary inline-block element-center"
                                                    style="width: 102px;">
                                                确定
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/js/plugins/datapicker/bootstrap-datepicker.zh-CN.js"></script>
<!-- NouSlider -->
<script src="/js/plugins/nouslider/nouislider.js"></script>

<script>

    var currentPage = 1;
    var totalPage = 1;
    var pageSize = 10;
    var myPatientDivHtml = $("#scheduling-div");
    var pagination = $('#pagination');
    var noRecords = $("#no-records");
    var therapistId = getCookie("profile_id");
    var buttonContent = $("#time-block-button");
    var vacationType = $("#vacation-type");
    var vacationDate = $("#vacation-date");
    var prescriptionItemId = null;
    var treatmentGroupId = null;
    var patientId = null;
    var dateInput = $("#date-input");
    var arrangedTimes = 0;//已经安排的还没有完成的任务
    var residueTimes = 0;//剩余次数

    var nowDate = new Date();
    var today = nowDate.format("YYYY-MM-DD");

    var monday = "";
    var sunday = "";

    var timeBlockArray = ["08:00~08:30", "08:35~09:05", "09:10~09:40", "09:45~10:15",
        "10:20~10:50", "10:55~11:25", "13:00~13:30", "13:35~14:05", "14:10~14:40", "14:45~15:15",
        "15:20~15:50", "15:55~16:25", "16:30~17:00"];

    var chooseTimeBlockStartDate = "";
    var chooseTimeBlockStartDateTmp = "";
    var chooseTimeBlockEndDate = "";
    var chooseTimeBlockEndDateTmp = "";

    var patientChooseHtml = $("#patient-choose");
    var typeUnderTable = 1;//记录下面一张表的过滤的类型

    var isWeekdayTimeBlock = 0; //1可以表示周程表弹出的时间块，其他则是下面的表格
    var GRecordId = ""; //1可以删除，其他不行

    var vacationRemark = $("#vacation-remark");
    //    var vacationDate = $("#vacation-date");
    var vacationRepeat = $("#vacation-repeat-choose");
    var timeSlider = document.getElementById('vacation-time-slider');
    var basicSlider = document.getElementById('basic_slider');
    var weeksSelector = $("#weeks-selector");

    calcMondayAndSunday(nowDate);
    initDate(monday, sunday);

    pageInit();

    getTherapistSchedulePeriods();

    //获取全部治疗项目
    getPrescriptionItemList(1, null, currentPage, pageSize, 1);

    initDatePicker();

    var offsetTop = 0;
    var modalDiv = $("#modal-choose-patient-div,#modal-schedule-div");
    modalDiv.on('touchmove', function (event) {
        event.preventDefault();
    }, false);
    $(window).scroll(function () {
        offsetTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
        modalDiv.attr('style', 'position:absolute;overflow:auto;top:' + offsetTop + "px;");
    });
    modalDiv.on("shown.bs.modal", function () {
        $(".modal-backdrop").attr("style", "position:absolute;top:" + offsetTop + "px;bottom:-" + offsetTop + "px");
    });



    function buildAddVacationDiv() {
        vacationRemark.val("");
        vacationType.prop("checked", false);
//        vacationDate.val(new Date().format("yyyy-MM-dd"));
        vacationDate.attr("value",new Date().format("yyyy-MM-dd"));
//        alert(vacationDate.val());
        timeSlider.noUiSlider.set(["9:00", "17:00"]);
        vacationRepeat.attr("value","0");
        $("#vacation-btn").attr("onclick", "addVacation()");
    }

    function buildUpdateVacationDiv(vacation) {
        var startTime = new Date(vacation.start_time).format("HH:mm");
        var endTime = new Date(vacation.end_time).format("HH:mm");
        vacationRemark.val(vacation.remark);

        vacationDate.attr("value",new Date(vacation.date).format("yyyy-MM-dd"));
        timeSlider.noUiSlider.set([startTime, endTime]);
        if (vacation.loop_weekday == null) {
            vacationRepeat.val("0");
        } else {
            vacationRepeat.val("1");
        }

        if (startTime == "08:00" && endTime == "18:00") {
            vacationType.prop("checked", true);
        } else {
            vacationType.prop("checked", false);
        }
        $("#vacation-btn").attr("onclick", "updateVacation(" + vacation.id + ")");
    }

    function addVacation() {
        if (vacationRemark.val() == null || vacationRemark.val() == "") {
            toastr.error("请填写标题！");
            return;
        }else if (vacationRemark.val().length > 15){
            toastr.error("标题请勿超过15个字！");
            return;
        }
        var times = timeSlider.noUiSlider.get();
        var sdate = getDate(vacationDate.val() + " " + times[0]);
        var edate = getDate(vacationDate.val() + " " + times[1]);

//        alert(sdate.getTime()+"||"+ edate.getTime());

        mandy_add_vacation(null, vacationRemark.val(), vacationRepeat.val() == "1", sdate.getTime(), edate.getTime(),
                function (date) {
                    toastr.success("添加成功！");
                    $('#modal-add-vacation-div').modal('hide');
                    getTherapistSchedulePeriods();
                });
    }

    function updateVacation(vacationId) {
        if (vacationRemark.val() == null || vacationRemark.val() == "") {
            toastr.error("请填写标题！");
            return;
        }

        var times = timeSlider.noUiSlider.get();
        var sdate = getDate(vacationDate.val() + " " + times[0]);
        var edate = getDate(vacationDate.val() + " " + times[1]);

        mandy_put_vacation(vacationId, vacationRemark.val(), vacationRepeat.val() == "1", sdate.getTime(), edate.getTime(), function (date) {
            toastr.success("修改成功！");
            $('#modal-add-vacation-div').modal('hide');
            getTherapistSchedulePeriods();
        });
    }

    function delVacation(vaId) {
        mandy_delete_vacation(vaId, function (data) {
            toastr.success("删除成功！");
            getTherapistSchedulePeriods();
        });
    }

    //date
    function addDay(date, num) {
//        debugger;
        var newDate = getDate(date);
        newDate = newDate.getTime();
        newDate = newDate + num * 24 * 60 * 60 * 1000;
        newDate = getDate(newDate);

        return newDate;
    }

    function subDay(date, num) {
        var newDate = date;
        newDate = newDate.valueOf();
        newDate = newDate - num * 24 * 60 * 60 * 1000;
        newDate = getDate(newDate);
        return newDate;
    }

    function calcMondayAndSunday(date) {
        var currentDate = date;
        var weekday = currentDate.getDay();
        switch (weekday) {
            case 0:
                monday = subDay(currentDate, 6);
                sunday = currentDate;
                break;
            case 1:
                monday = currentDate;
                sunday = addDay(currentDate, 6);
                break;
            case 2:
                monday = subDay(currentDate, 1);
                sunday = addDay(currentDate, 5);
                break;
            case 3:
                monday = subDay(currentDate, 2);
                sunday = addDay(currentDate, 4);
                break;
            case 4:
                monday = subDay(currentDate, 3);
                sunday = addDay(currentDate, 3);
                break;
            case 5:
                monday = subDay(currentDate, 4);
                sunday = addDay(currentDate, 2);
                break;
            case 6:
                monday = subDay(currentDate, 5);
                sunday = addDay(currentDate, 1);
                break;
            default:
                break;
        }
    }

    function lastWeek() {
//        debugger;
//        clearWeekTable();
        monday = subDay(monday, 7);
        sunday = subDay(sunday, 7);
        initDate(monday, sunday);
        getTherapistSchedulePeriods();
    }

    function nextWeek() {
//        clearWeekTable();
        monday = addDay(monday, 7);
        sunday = addDay(sunday, 7);
        initDate(monday, sunday);
        getTherapistSchedulePeriods();
    }

    function initDate(day1, day2) {
        var dayStart = day1.format("yyyy-MM-dd");
        var dayEnd = day2.format("yyyy-MM-dd");
        $("#week-periods-date").text(dayStart + " ～ " + dayEnd);

        $("#week-1").text(day1.format("(MM月DD日)"));
        $("#week-2").text(addDay(day1, 1).format("(MM月DD日)"));
        $("#week-3").text(addDay(day1, 2).format("(MM月DD日)"));
        $("#week-4").text(addDay(day1, 3).format("(MM月DD日)"));
        $("#week-5").text(addDay(day1, 4).format("(MM月DD日)"));
        $("#week-6").text(addDay(day1, 5).format("(MM月DD日)"));
        $("#week-7").text(day2.format("(MM月DD日)"));
        tagToday(day1);

        addTimeBlockAttr("MON", getDate(monday).format("YYYY-MM-DD"));
        addTimeBlockAttr("TUE", getDate(addDay(monday, 1)).format("YYYY-MM-DD"));
        addTimeBlockAttr("WED", getDate(addDay(monday, 2)).format("YYYY-MM-DD"));
        addTimeBlockAttr("THU", getDate(addDay(monday, 3)).format("YYYY-MM-DD"));
        addTimeBlockAttr("FRI", getDate(addDay(monday, 4)).format("YYYY-MM-DD"));
        addTimeBlockAttr("SAT", getDate(addDay(monday, 5)).format("YYYY-MM-DD"));
        addTimeBlockAttr("SUN", getDate(sunday).format("YYYY-MM-DD"));
    }

    function tagToday(monday) {
        for (var i = 0; i < 7; i++) {
            if (addDay(monday, i).format("YYYY-MM-DD") == today) {
                $("#td-" + (i + 1)).addClass("today-border");
            }
            else {
                $("#td-" + (i + 1)).removeClass("today-border");
            }
        }
    }

    function addTimeBlockAttr(idPre, day) {
        for (var i = 1; i <= 13; i++) {
            $("#" + idPre + "-" + i).attr("data-time-block-start", day + " " + timeBlockArray[i - 1].split("~")[0]);
            $("#" + idPre + "-" + i).attr("data-time-block-end", day + " " + timeBlockArray[i - 1].split("~")[1]);
        }
    }

    //初始化页面
    function pageInit() {
        pagination.jqPagination({
            max_page: totalPage, //设置最大页 默认为1
            current_page: currentPage, //设置当前页 默认为1
            page_string: '当前第{current_page}页,共{max_page}页',
            paged: function (page) {
                if (page != currentPage) {
                    var scrollY = $(document).scrollTop();
                    getPrescriptionItemList($("#patient-select").val(), new Date().valueOf(), page, pageSize, 1, scrollY);
                    currentPage = page;
                }
            }
        });

        // Add responsive to jqGrid
        $("#my-patient-list").bind('resize', function () {
            var width = $('#my-patient-list').width();
            $("#my-patient").setGridWidth(width);
        });


        noUiSlider.create(timeSlider, {
                    start: [0, 20],
                    connect: true,
                    step: 1,
                    tooltips: [true, true],
                    margin: 1,
                    range: {
                        'min': 0,
                        'max': 20
                    },
                    format: {
                        to: function (value) {
                            var hour = parseInt(value / 2) + 8;
                            var min = value % 2 == 0 ? "00" : "30";
                            return hour + ":" + min;
                        },
                        from: function (value) {
                            var v = value.split(":");
                            var hour = parseInt(v[0]);
                            var min = v[1];
                            hour -= 8;
                            if (min == "30") {
                                return hour * 2 + 1;
                            } else {
                                return hour * 2;
                            }


                            return value.replace(',-', '');
                        }
                    }
                }
        );

        timeSlider.noUiSlider.on("update", function (value, handle) {
            if (value[0] == "8:00" && value[1] == "18:00") {
                vacationType.prop("checked", true);
            } else {
                vacationType.prop("checked", false);
            }
        });

        vacationType.bind("change", function (event) {

            if ($(event.target).is(':checked')) {
                timeSlider.noUiSlider.set(["8:00", "18:00"]);
            } else {
                timeSlider.noUiSlider.set(["9:00", "17:00"]);
            }
        });

        noUiSlider.create(basicSlider, {
                    start: [1],
                    connect: [true,false],
                    step: 1,
                    tooltips: [true],
                    margin: 1,
                    range: {
                        'min': 0,
                        'max': 10
                    },
                    format: {
                        to: function (value) {
                            return value;
                        },
                        from: function (value) {
                            return value;
                        }
                    }
                }
        );


    }


    function getPrescriptionItemList(type, date, page, pageSize, option, scrollY) {
//        debugger;
        var searchKey = null;
        if (1 == option) {
            $("#search-key").val(null);
        }
        if (2 != option) {
            searchKey = $("#search-key").val();
        }
        mandy_get_my_prescription_item_list(searchKey, page, pageSize, type, date, 2, function (data) {
            if (1 == option || 3 == option) {
                buildJqTable(data);
                if (window.scrollY) {
                    window.scroll(0, scrollY);  // reset the scroll position to the top left of the document.
                }
            }
            else {
                buildPatientDiag(data);
            }
        });
    }

    //    function getPrescriptionItemList2(type, date, page, pageSize) {
    ////        debugger;
    //        mandy_get_my_prescription_item_list(page, pageSize, type, date, function (data) {
    //            buildPatientDiag(data);
    //        });
    //    }

    //对话框病患表
    function buildPatientDiag(data) {
        patientChooseHtml.empty();
        var option = $("<option value='0'>请选择患者</option>");
        patientChooseHtml.append(option);

        if (data.list == null || data.list.length == 0) {
            return;
        }

        var patientIds = [];

        var newList = [];

        $.each(data.list, function (idx, val) {
            var patientId = "\"" + val.prescription.medical_record.patient.id + "\"";
            if (patientIds[patientId] != null) {
                if (patientIds[patientId] > val.prescription.create_time) {
                    patientIds[patientId] = val.prescription.create_time;
                    newList[patientId] = val;
                }
            }
            else {
                newList[patientId] = val;
            }
        });

//            debugger;
        makePatientOption(newList);
    }

    function makePatientOption(list) {
        for (var id in list) {
            var val = list[id];
//            debugger;
            var patientId = val.prescription.medical_record.patient.id;
            var prescriptionItemId = val.id;
            var treatmentGroupId = null;
            if (val.treatment_group != null) {
                treatmentGroupId = val.treatment_group.id;
            }
            var patientName = getPrivatePatientName(val.prescription.medical_record.patient.name);
            var patientSex = sexArray[val.prescription.medical_record.patient.sex];
            var patientAge = calculateAge(val.prescription.medical_record.patient.birthday);
            var EMRNum = val.prescription.medical_record.number;

            var option = $("<option>");
            option.attr("data-prescription-item-id", prescriptionItemId);
            option.attr("data-patient-id", patientId);
            option.attr("data-group-id", treatmentGroupId);
            option.attr("data-residue-times", val.residue_times);
            option.append(EMRNum + "-" + patientName + "-" + patientSex + "-" + patientAge);
            patientChooseHtml.append(option);
        }

    }

    //康复训练病患表
    function buildJqTable(data, scrollY) {
        if (data == null) {
            return;
        }

        currentPage = data.current_page;
        totalPage = data.total_page;
        if (totalPage == 0) {
            totalPage = 1;
        }
        pagination.jqPagination('option', 'current_page', currentPage);
        pagination.jqPagination('option', 'max_page', totalPage);

        if (data.list == null) {
            data.list = [];
            noRecords.show();
        }
        else if (data.list.length != 0) {
            noRecords.hide();
        }
        else {
            noRecords.show();
        }

        var index = 1;

        myPatientDivHtml.empty();
        myPatientDivHtml.append("<table id='my-patient' style='text-align: center;'></table>");
        $("#my-patient").jqGrid({
            data: data.list,
            datatype: "local",
            height: "auto",
            autowidth: true,
            shrinkToFit: true,
            rowNum: pageSize,
//            rownumbers: true,
            colNames: ['序号', '患者编号', '姓名', '性别', '年龄', '类型', '剩余次数', '上一次训练时间', "操作", "查看"],
            colModel: [
                {
                    name: 'index',
                    index: 'index',
                    width: 40,
                    align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        return index++;
                    }
                },
                {
                    name: 'prescription.medical_record.number',
                    index: 'prescription.medical_record.number',
                    width: 90,
                    align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        return "<span data_my_data=" + rowObject.prescription.medical_record.id + ">" + cellvalue + "</span>";
                    }

                },
                {
                    name: 'prescription.medical_record.patient.name',
                    index: 'prescription.medical_record.patient.name',
                    width: 90,
                    align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        return "<span data_my_data=" + rowObject.prescription.medical_record.patient.id + ">" + getPrivatePatientName(cellvalue) + "</span>";
                    }
                },
                {
                    name: 'prescription.medical_record.patient.sex',
                    index: 'prescription.medical_record.patient.sex',
                    width: 50,
                    align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == "female") {
                            return "<span data_my_data=" + cellvalue + ">" + "女" + "</span>";
                        }
                        else if (cellvalue == "male") {
                            return "<span data_my_data=" + cellvalue + ">" + "男" + "</span>";
                        }
                        else {
                            return "<span>未知</span>";
                        }
                    }
                },
                {
                    name: 'prescription.medical_record.patient.birthday',
                    index: 'prescription.medical_record.patient.birthday',
                    width: 50,
                    align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return "<span data_my_data=" + cellvalue + ">" + calculateAge(cellvalue) + "</span>";
                        }
                    }
                },
                {
                    name: 'prescription.type', index: 'prescription.type', width: 60, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        if (1 == cellvalue) {
                            return "<span data_my_data=" + cellvalue + ">" + "康复评估" + "</span>";
                        }
                        else {
                            return "<span data_my_data=" + cellvalue + ">" + "康复训练" + "</span>";
                        }
                    }
                },
                {
                    name: 'residue_times', index: 'residue_times', width: 90, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            return "<span class='' data_my_data=" + cellvalue + ">" + cellvalue + "</span>";
                        }
                        else {
                            return "<span></span>";
                        }
                    }
                },
                {
                    name: 'last_training_time', index: 'last_training_time', width: 120, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue != null) {
                            var dateTime = getDate(cellvalue).format("YYYY-MM-DD HH:mm");
                            return "<span data_my_data=" + cellvalue + ">" + dateTime + "</span>";
                        }
                        else {
                            return "<span></span>";
                        }
                    }
                },
                {
                    name: 'option',
                    index: 'option',
                    width: 50, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        prescriptionItemId = rowObject.id;
                        if (rowObject.treatment_group != null) {
                            treatmentGroupId = rowObject.treatment_group.id;
                        }
                        patientId = rowObject.prescription.medical_record.patient.id;
                        var residueTime = rowObject.residue_times;
                        return '<a onclick=\'isWeekdayTimeBlock=0;handleSchedule(null,' + prescriptionItemId + ',' +
                                patientId + ',' + treatmentGroupId + ',\"' + new Date().format("YYYY-MM-DD") +
                                '\",' +residueTime+')\'' +
                                'data-toggle="modal" href="#modal-schedule-div" style="text-decoration:none;color:#fff;padding:5px 10px;background-color: #36CDEA; border-radius: 14px;">排课</a>';
                    }
                },
                {
                    name: 'lookup',
                    index: 'lookup',
                    width: 50, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {

                        var param = {};
                        param.emr_id = rowObject.prescription.medical_record.id;

                        var a = $("<a>");
                        a.attr("style", "text-decoration:none;color:#fff;padding:5px 10px;background-color: #42D0A7; border-radius: 14px;");
                        a.attr("onclick", "setParamToUrl(" + JSON.stringify(param) + ");loadTitle('/emr/info-title.html');");
                        a.text("病历");
                        return a.prop("outerHTML");
                    }
                }
            ],
            viewrecords: true,
            hidegrid: false,
            onSelectRow: function (trId, status) {
            },
            onSortCol: function (idx, iCol, sortorder) {
                index = index - data.list.length;
            }
           
        });
        $("#my-patient tr:even").css("background","#F6F6F6");
    }

    function initDatePicker() {
        //debugger;

        dateInput.datepicker({
            defaultDate: new Date().format("yyyy-MM-dd"),
//            format:"yyyy-MM-dd",
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: false,
            autoclose: true,
            language: "zh-CN"
//            endDate: "+1m",
//            startDate: "0d"
        });

        vacationDate.datepicker({
            defaultDate: new Date().format("yyyy-MM-dd"),
//            format:"yyyy-MM-dd",
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: false,
            autoclose: true,
            language: "zh-CN",
//            endDate: "+1m",
            startDate: "0d"
        });


        dateInput.datepicker().on("changeDate", function (e) {
            if (isWeekdayTimeBlock == 1) {
                restoreHandleSchedule(null, null, null, null, e.date.format("YYYY-MM-DD"));
            }
            else {
                buttonContent.empty();
                mandy_get_therapist_schedule(therapistId, e.date.getTime(), function (data) {
                    $.each(data.time_block_list, function (idx, val) {

                        var divButton = $("<div class='col-sm-3' style='text-align:center;padding: 0;margin: 0.5vw 0;'>");
                        var button = $("<button class='btn' type='button' style='width: 102px;height: 34px;'>");
                        button.prop("id", "time-block-" + (idx + 1));
                        button.attr("start_time", val.start_time);
                        button.attr("end_time", val.end_time);
                        button.attr("record_id", val.record_id);
                        button.text(getDate(val.start_time).format("HH:mm") + "-" + getDate(val.end_time).format("HH:mm"));
                        button.attr("onclick", "setSelectedTime(this)");

                        /**
                         * 时间块状态
                         * 1：已过期并且未安排
                         * 2：已过期并且已安排
                         * 3：已过期并且已安排并且已完成
                         * 4：已过期并且已安排并且已取消
                         *
                         * 5：进行中并且未安排
                         * 6：进行中并且已安排
                         * 7：进行中并且已安排并且已完成
                         * 8：进行中并且已安排并且已取消
                         *
                         * 9： 未过期并且未安排
                         * 10：未过期并且已安排
                         * 11：未过期并且已安排并且已完成
                         * 12：未过期并且已安排并且已取消
                         */

                        //6、10
                        if (6 == val.status || 10 == val.status) {
                            //当前治疗项目
                            if (val.prescription_item_id != null && val.prescription_item_id == prescriptionItemId) {
                                if (isWeekdayTimeBlock != null && isWeekdayTimeBlock == 1 && compareTimeBlock(val.start_time, val.end_time)) {
                                    button.addClass("btn-primary");
                                    button.prop("disabled", false);
                                }
                                else {
//                            button.addClass("button-disabled");
//                            button.prop("disabled", true);
                                    button.addClass("button-normal");
                                    button.prop("disabled", false);
                                }

                            } else {
//                        button.addClass("button-disabled");
//                        button.prop("disabled", true);
                                button.addClass("button-normal");
                                button.prop("disabled", false);
                            }
                        }
                        //5、9，7，8，11，12
                        else if (5 == val.status || 9 == val.status || 7 == val.status || 8 == val.status || 10 == val.status
                                || 11 == val.status || 12 == val.status  ) {
                            button.addClass("button-normal");
                            button.prop("disabled", false);
                        }
                        //1，2，3，4
                        else {
                            button.addClass("button-disabled");
                            button.prop("disabled", true);
                        }

                        divButton.append(button);
                        buttonContent.append(divButton);
                    });
                });
            }

        });

//        dateInput.attr("value",new Date().format("yyyy-MM-dd"));
        dateInput.attr("value",new Date().format("yyyy-MM-dd"));
//        vacationDate.val(new Date().format("yyyy-MM-dd"));
        vacationDate.attr("value",new Date().format("yyyy-MM-dd"));
    }

    function handleSchedule(rowObj, prcpItemId, pid, gid, day ,residueTime) {
        chooseTimeBlockStartDateTmp = "";
        chooseTimeBlockEndDateTmp = "";
        residueTimes = residueTime;

        weeksSelector.removeClass("hide");

        if (rowObj != null) {
            prescriptionItemId = rowObj.id;
            if (rowObj.treatment_group != null) {
                treatmentGroupId = rowObj.treatment_group.id;
            }
            patientId = rowObj.prescription.medical_record.patient.id;
            residueTimes = rowObj.residue_times;
        }
        if (prcpItemId != null) {
            prescriptionItemId = prcpItemId;
        }

        if (pid != null) {
            patientId = pid;
        }

        if (gid != null) {
            treatmentGroupId = gid;
        }

        if (day != null) {
//            debugger;
//            dateInput.attr("value",getDate(day).format("yyyy-MM-dd"));;
            dateInput.attr("value",getDate(day).format("yyyy-MM-dd"));
        }
//        else {
//            dateInput.attr("value",new Date().format("yyyy-MM-dd"));
//        }

        if (dateInput.val() == null || dateInput.val() == "") {
            return;
        }

        var date = getDate(Date.parse(dateInput.val()));
        dateInput.datepicker('setDate', dateInput.val());

        basicSlider.noUiSlider.on('update', function ( values, handle ) {
            changeSlider();
        });
    }

    function changeSlider(){
        debugAlert("-------------changeSlider--------------------");
        var selectedButton = buttonContent.find("button.btn-primary").length;
        if(selectedButton == 0) {
            selectedButton = 1;
        }
        var value = basicSlider.noUiSlider.get();
        debugAlert("-------------value--------------------" + value);
        debugAlert("-------------selectedButton--------------------" + selectedButton);
        debugAlert("-------------residueTimes--------------------" + residueTimes);

        if ( value < 1 ) {
            basicSlider.noUiSlider.set(1);
        } else if ( value * selectedButton > residueTimes ) {
            debugAlert("-------------1111111--------------------" + value * selectedButton);
            var res = parseInt(residueTimes / selectedButton);
            res = res < 0 ? 1 : res;
            basicSlider.noUiSlider.set(res);
        }
    }

    function restoreHandleSchedule(rowObj, prcpItemId, pid, gid, day) {
        weeksSelector.addClass("hide");
        if (rowObj != null) {
            prescriptionItemId = rowObj.id;
            if (rowObj.treatment_group != null) {
                treatmentGroupId = rowObj.treatment_group.id;
            }
            patientId = rowObj.prescription.medical_record.patient.id;
            residueTimes = rowObj.residue_times;
        }

        if (prcpItemId != null) {
            prescriptionItemId = prcpItemId;
        }

        if (pid != null) {
            patientId = pid;
        }

        if (gid != null) {
            treatmentGroupId = gid;
        }

        if (day != null) {
//            debugger;
            dateInput.attr("value",getDate(day).format("yyyy-MM-dd"));;
        }
//        else {
//            dateInput.attr("value",new Date().format("yyyy-MM-dd"));
//        }

        if (dateInput.val() == null || dateInput.val() == "") {
            return;
        }

        var date = getDate(Date.parse(dateInput.val()));
        buttonContent.empty();

        mandy_get_therapist_schedule(therapistId, date.getTime(), function (data) {


            $.each(data.time_block_list, function (idx, val) {

                var divButton = $("<div class='col-sm-3' style='text-align:center;padding: 0;margin: 0.5vw 0;'>");
                var button = $("<button class='btn' type='button' style='width: 102px;height: 34px;'>");

                button.prop("id", "time-block-" + (idx + 1));
                button.attr("start_time", val.start_time);
                button.attr("end_time", val.end_time);
                button.attr("record_id", val.record_id);
                button.text(getDate(val.start_time).format("HH:mm") + "-" + getDate(val.end_time).format("HH:mm"));
                button.attr("onclick", "setSelectedTime(this)");

                /**
                 * 时间块状态
                 * 1：已过期并且未安排
                 * 2：已过期并且已安排
                 * 3：已过期并且已安排并且已完成
                 * 4：已过期并且已安排并且已取消
                 *
                 * 5：进行中并且未安排
                 * 6：进行中并且已安排
                 * 7：进行中并且已安排并且已完成
                 * 8：进行中并且已安排并且已取消
                 *
                 * 9： 未过期并且未安排
                 * 10：未过期并且已安排
                 * 11：未过期并且已安排并且已完成
                 * 12：未过期并且已安排并且已取消
                 */

                //6、10
                if (6 == val.status || 10 == val.status) {
                    //当前治疗项目
                    if (val.prescription_item_id != null && val.prescription_item_id == prescriptionItemId) {
                        if (isWeekdayTimeBlock != null && isWeekdayTimeBlock == 1 && compareTimeBlock(val.start_time, val.end_time)) {
                            //取消选中
                            if (chooseTimeBlockStartDateTmp == null || chooseTimeBlockEndDateTmp == null) {
                                button.addClass("button-normal");
                                button.prop("disabled", false);
                            }
                            //选中了一个并且不是原来的
                            else if (chooseTimeBlockStartDateTmp != "" && chooseTimeBlockEndDateTmp != "" && !compareTimeBlock(chooseTimeBlockStartDateTmp, chooseTimeBlockEndDateTmp)) {
                                button.addClass("button-normal");
                                button.prop("disabled", false);
                            }
                            else {
                                button.addClass("btn-primary");
                                button.prop("disabled", false);
                            }
                        } else {
//                            button.addClass("button-disabled");
//                            button.prop("disabled", true);
                              button.addClass("button-normal");
                              button.prop("disabled", false);
                        }

                    }
                    else {
//                        button.addClass("button-disabled");
//                        button.prop("disabled", true);
                        button.addClass("button-normal");
                        button.prop("disabled", false);
                    }
                }
                //5、9，7，8，11，12
                else if (5 == val.status || 9 == val.status || 7 == val.status || 8 == val.status || 10 == val.status
                        || 11 == val.status || 12 == val.status) {
                    button.addClass("button-normal");
                    button.prop("disabled", false);
                }
                //1，2，3，4,13
                else {
                    button.addClass("button-disabled");
                    button.prop("disabled", true);
                }

                if (chooseTimeBlockStartDateTmp == val.start_time && chooseTimeBlockEndDateTmp == val.end_time) {
                    button.addClass("btn-primary");
                    button.prop("disabled", false);
                }

                divButton.append(button);
                buttonContent.append(divButton);
            });
        });

    }

    function strTimeToNumber(time) {
        if (typeof (time) == "string" && time.indexOf(" ") == -1 && time.indexOf("-") == -1 && time.indexOf("/") == -1 && time.indexOf("\"")) {
            return parseInt(time);
        }

        return time;
    }

    function compareTimeBlock(startTime, endTime) {

        startTime = strTimeToNumber(startTime);
        endTime = strTimeToNumber(endTime);

        var date1 = getDate(startTime).format("YYYY-MM-DD hh:mm");
        var time1 = getDate(date1).getTime();
        var date2 = getDate(endTime).format("YYYY-MM-DD hh:mm");
        var time2 = getDate(date2).getTime();

        if (time1 >= getDate(chooseTimeBlockStartDate).getTime()
                && time1 < getDate(chooseTimeBlockEndDate).getTime()
                && time2 > getDate(chooseTimeBlockStartDate).getTime()
                && time2 <= getDate(chooseTimeBlockEndDate).getTime()) {
            return true;
        }
    }

    function setSelectedTime(event) {
        var isHas = false;
        if ($(event).hasClass("btn-primary")) {
            isHas = true;
        }

        if (isWeekdayTimeBlock == 1) {
            var buttons = $("#time-block-button").children("div");

            if (buttons != null && buttons.length > 0) {
                $.each(buttons, function (idx, v) {
                    v = $(v).children("button")[0];
                    if ($(v).hasClass("btn-primary")) {
                        $(v).removeClass("btn-primary");
                        $(v).addClass("button-normal");
                    }
                });
            }

            if (isHas) {
                chooseTimeBlockStartDateTmp = null;
                chooseTimeBlockEndDateTmp = null;
            }
            else {
                chooseTimeBlockStartDateTmp = $(event).attr("start_time");
                chooseTimeBlockEndDateTmp = $(event).attr("end_time");
            }
        }

        if (isHas) {
            $(event).removeClass("btn-primary");
            $(event).addClass("button-normal");
        }
        else {
            $(event).removeClass("button-normal");
            $(event).addClass("btn-primary");
        }

        changeSlider();
    }

    function submit() {
        var timeListAdd = [];
        var recordListDel = [];
        if (isWeekdayTimeBlock == 1) {
            //取消选中
            if (chooseTimeBlockStartDateTmp == null || chooseTimeBlockEndDateTmp == null) {
                recordListDel.push(GRecordId);
            }
            //选中了一个并且不是原来的
            else if (chooseTimeBlockStartDateTmp != "" && chooseTimeBlockEndDateTmp != "" && !compareTimeBlock(chooseTimeBlockStartDateTmp, chooseTimeBlockEndDateTmp)) {
                var timeBlockTmp = {};
                timeBlockTmp.start_time = chooseTimeBlockStartDateTmp;
                timeBlockTmp.end_time = chooseTimeBlockEndDateTmp;
                recordListDel.push(GRecordId);
                timeListAdd.push(timeBlockTmp);
            }

            if (timeListAdd.length == 0 && recordListDel.length == 0) {
                toastr.error("没有做出任何安排");
                return;
            }

            mandy_put_therapist_schedule(prescriptionItemId, null, patientId, timeListAdd, recordListDel, function (data) {
//            clearWeekTable();
                getPrescriptionItemList(typeUnderTable, new Date().valueOf(), currentPage, pageSize, 1);
                getTherapistSchedulePeriods();
                toastr.success("修改成功");
                $("#modal-schedule-div").modal('hide');
            });
        }
        else {
            var selectTimeBlockList = buttonContent.children();
            $.each(selectTimeBlockList, function (idx, val) {
                val = $(val).children("button")[0];
                if ($(val).hasClass("btn-primary")) {
                    var timeBlock = {};
                    timeBlock.start_time = $(val).attr("start_time");
                    timeBlock.end_time = $(val).attr("end_time");
                    timeListAdd.push(timeBlock);
                }

                if ($(val).hasClass("button-normal") && $(val).attr("record_id") != null) {
                    recordListDel.push($(val).attr("record_id"));
                }
            });
            
            // 未选择任何时间块时提示
            if (timeListAdd.length == 0) {
                toastr.error("没有做出任何安排");
                return;
            }

            mandy_post_therapist_schedule(prescriptionItemId, null, basicSlider.noUiSlider.get(), timeListAdd, function
                    (data) {
                getPrescriptionItemList(typeUnderTable, new Date().valueOf(), currentPage, pageSize, 1);
                getTherapistSchedulePeriods();
                toastr.success("修改成功");
                $("#modal-schedule-div").modal('hide');
            });
        }


    }

    //点击周程表空白时间块确定
    function submit2(id) {
        if (0 == $("#" + id).val()) {
            toastr.error("请选择患者");
            return;
        }
//        debugger;
        var timeListAdd = [];
        var timeBlock = {};
        timeBlock.start_time = getDate(chooseTimeBlockStartDate).getTime();
        timeBlock.end_time = getDate(chooseTimeBlockEndDate).getTime();
        timeListAdd.push(timeBlock);

        if (timeListAdd.length == 0) {
            toastr.error("没有做出任何安排");
            return;
        }

        mandy_put_therapist_schedule(prescriptionItemId, null, patientId, timeListAdd, null, function (data) {
//            clearWeekTable();
            getPrescriptionItemList(typeUnderTable, new Date().valueOf(), currentPage, pageSize, 1);
            getTherapistSchedulePeriods();
            toastr.success("修改成功");
            $("#modal-choose-patient-div").modal('hide');
        });
    }

    function getTherapistSchedulePeriods() {
        clearOfFillTd(1);
        mandy_get_therapist_schedule_periods(null, monday.valueOf(), sunday.valueOf(), function (data) {
            if (data.treatment_record_list != null) {
                $.each(data.treatment_record_list, function (idx, val) {
                    buildTaskTd(val);
                });
            }

//            if (data.gauge_record_list != null) {
//                $.each(data.gauge_record_list, function (idx, val) {
//                    buildTaskTd(val);
//                });
//            }

            clearOfFillTd(2);
        });
        var monday0 = new Date(monday.valueOf()).setHours(0, 0, 0, 0);
        var sunday0 = new Date(sunday.valueOf());
        sunday0.setHours(0, 0, 0 ,0);
        sunday0 = sunday0.setDate(sunday0.getDate() + 1);
        mandy_get_vacation(null, null, monday0, sunday0, function (data) {
            $.each(data.vacation_list, function (idx, vacation) {

                var start;
                var end;
                if (vacation.loop_weekday == null) {
                    start = new Date(vacation.date).format("yyyy-MM-dd") + " " + new Date(vacation.start_time).format("HH:mm");
                    end = new Date(vacation.date).format("yyyy-MM-dd") + " " + new Date(vacation.end_time).format("HH:mm");

                } else {

                    var d = new Date(monday.valueOf());
                    var addDay = vacation.loop_weekday - 1;
                    addDay = addDay < 0 ? addDay + 7 : addDay;
                    d.setDate(d.getDate() + addDay);

                    start = d.format("yyyy-MM-dd") + " " + new Date(vacation.start_time).format("HH:mm");
                    end = d.format("yyyy-MM-dd") + " " + new Date(vacation.end_time).format("HH:mm");
                }

                $("#one-week-schedule td").each(function (idx, td) {
                    td = $(td);
                    var sStart = td.attr("data-time-block-start");
                    var sEnd = td.attr("data-time-block-end");
                    if (sStart != null && sEnd != null) {
                        if (!(sEnd <= start || sStart >= end)) {
                            td.text("休假");
                            clearTdAttr(td);
                            var divForm = $('<div class="ibox-content vacation-edit-div"  style="width:250px; min-height:130px; border: 1px #cccccc solid;padding-bottom: 0px;padding-left: 10px;padding-right: 10px" id="data-vacation">');
                            var vacationNameDiv = $('<div class="" style="padding-bottom: 10px;text-align: left;">');
                            vacationNameDiv.html("休假提示:");
                            var vacationRemarkDiv = $('<div class="" style="padding-bottom: 10px;">');
                            vacationRemarkDiv.html(vacation.remark);
                            var vacationTimeDiv = $('<div class="patient-div" style="">');
                            vacationTimeDiv.text(start + "~" + end);

                            var vacationActDiv = $('<div style="text-align: right;border-top: 1px #cccccc solid; padding-top: 5px;padding-bottom: 10px;">');
                            var btnEdit = $('<span class="" id="btn-edit" style="cursor: pointer;color: #40a6cb;">');
                            btnEdit.text("编辑");
                            btnEdit.attr("onclick", "$(\"#modal-add-vacation-div\").modal(\"show\");buildUpdateVacationDiv(" + JSON.stringify(vacation) + ")");
                            var line = $('<span class="" style="margin: 0 2px">');
                            line.text("|");
                            var btnDel = $('<span class="" id="btn-del" style="cursor: pointer;color: #fa9b9b;">');
                            btnDel.text("删除");
                            btnDel.attr("onclick", "delVacation(" + vacation.id + ")");
                            vacationActDiv.append(btnEdit);
                            vacationActDiv.append(line);
                            vacationActDiv.append(btnDel);
                            divForm.append(vacationNameDiv);
                            divForm.append(vacationRemarkDiv);
                            divForm.append(vacationTimeDiv);
                            divForm.append(vacationActDiv);
                            td.append(divForm);
                            $(td).addClass("alt");
                        }
                    }
                });
            });
        });
    }

    function buildTaskTd(val) {
        var patientId = val.patient.id;
        var patientName = getPrivatePatientName(val.patient.name);
        var patientSex = sexArray[val.patient.sex];
        var patientAge = calculateAge(val.patient.birthday);

        var recordId = val.id;

        //var EMRNum = cutEMRNumber(val.prescription_item.prescription.medical_record.number);
        var EMRNum = val.prescription_item.prescription.medical_record.number;
        var startTime = val.start_time;
        var endTime = val.end_time;
        var status = val.status;

        var totalTimes = val.prescription_item.times;
        var notFinishTimes = val.prescription_item.times - val.prescription_item.execution_times;

        var typeNumber = val.prescription_item.prescription.type;
        var typeName = "";
        var resText = "";
        var prescriptionItemId = "";
        var treatmentGroupId = "";

        if (1 == typeNumber) {
            resText = val.gauge.name;
            typeName = "康复评估";
        }
        else {
            prescriptionItemId = val.prescription_item.id;
            treatmentGroupId = val.treatment_group.id;
            resText = "未完成次数/总次数：" + notFinishTimes + "/" + totalTimes;
            typeName = "康复训练";
        }

        var td = getWeekDayTd(startTime);

        if (td != null) {
            var divTdChild = $("<div style='width: 100%;border: 1px solid white'>");

            //悬浮框
            var divBox = $("<div class='ibox' style='width: 250px;'>");
            if (1 == typeNumber) {
                divBox.addClass("gauge");
            }
            else {
                divBox.addClass("training");
                $(td).hoverDelay({
                    hoverEvent: function () {
                        divBox.addClass("hover-show");
                    },
                    outEvent: function () {
                        divBox.removeClass("hover-show");
                    }
                });
            }
            var divContent = $('<div class="ibox-content" style="border: none;padding-bottom: 0px;padding-left: 10px;padding-right: 10px">');
            var divForm = $('<div class="form-group" id="data-patient">');
            var div1 = $('<div class="">');
            var divPatientName = $('<div class="patient-div" style="">');
            divPatientName.html(EMRNum + "&nbsp;&nbsp;&nbsp;&nbsp;" + patientName + "&nbsp;&nbsp;&nbsp;&nbsp;" + patientSex + "&nbsp;&nbsp;&nbsp;&nbsp;" + patientAge);

            var div2 = $('<div style="text-align: center;height: 30px;">');
            var divType = $('<div class="patient-div" style="">');
            divType.text(typeName);
            var divResidueTimes = $('<div style="width: 70%;display: inline-block;">');
            divResidueTimes.text(resText);


            div1.append(divPatientName);
            div2.append(divType);
            div2.append(divResidueTimes);
            divForm.append(div1);
            divForm.append(div2);
            divContent.append(divForm);
            divBox.append(divContent);

            //td顶部
            var topTag = $("<div style='height:18px;width: 100%;'>");
            var divImg1 = $('<div class="" style="text-align: left;padding-left:2px;font-size: 13px;font-weight: bold;width: 80%;display: inline-block;>">');
            divImg1.text(typeName);
            topTag.append(divImg1);

            //病历号 病患名
            var a = $('<a style="color:rgb(103, 106, 108);text-align: left;width:100%;padding-left: 2px;display: block;">');
            var divEMRNumTxt = $('<div style="font-size: 12px;white-space:nowrap;text-overflow:ellipsis; -o-text-overflow:ellipsis;overflow: hidden;">');
            divEMRNumTxt.text(EMRNum);
            var divPatientNameTxt = $('<div style="font-size: 12px;">');
            divPatientNameTxt.text(patientName);
            a.append(divEMRNumTxt, divPatientNameTxt);

            if (1 == status) {
                $(divTdChild).css("background-color", "#f5f4f5");
                var divImg2Container = $("<div style='width: 20%;display: inline-block;'>")
                var divImg2 = $('<i class="fa fa-star" style="color:#1ab394;font-size: 13px;text-align:right;margin-right: 2px;">');
                divImg2Container.append(divImg2);
                topTag.append(divImg2Container);
            }
            else if (2 == status) {
                $(divTdChild).css("background-color", "#f5f4f5");
                var divImg2Container = $("<div style='width: 20%;display: inline-block;'>")
                var divImg2 = $('<i class="fa fa-star-o" style="font-size: 13px;text-align:right;margin-right: 2px;">');
                divImg2Container.append(divImg2);
                topTag.append(divImg2Container);
            }
            else {
                if (typeNumber == 2) {
                    var time1 = $(td).attr("data-time-block-start");
                    var time2 = $(td).attr("data-time-block-end");

                    if (new Date() < getDate($(td).attr("data-time-block-end"))) {
                        var div3 = $('<div style="text-align: right;border-top: 1px #cccccc solid; padding-top: 5px;">');
                        var btnEdit = $('<span class="" id="btn-edit" style="cursor: pointer;color: #40a6cb;">');
                        btnEdit.text("编辑");
                        btnEdit.attr("onclick", "$('#modal-schedule-div').modal('show');GRecordId=\"" + recordId + "\";chooseTimeBlockStartDate=\"" + time1 + "\";chooseTimeBlockEndDate=\"" + time2 + "\";" + "isWeekdayTimeBlock=1;handleSchedule(null," + prescriptionItemId + "," + patientId + "," + treatmentGroupId + ",\"" + $(td).attr("data-time-block-start") + "\")");
                        var line = $('<span class="" style="margin: 0 2px">');
                        line.text("|");
                        var btnDel = $('<span class="" id="btn-del" style="cursor: pointer;color: #fa9b9b;">');
                        btnDel.text("删除");
                        btnDel.attr("onclick", "del(" + val.id + ")");
                        div3.append(btnEdit);
                        div3.append(line);
                        div3.append(btnDel);
                        divForm.append(div3);
                        a.attr("data-toggle", "modal");
                        a.attr("data-target", "#modal-schedule-div");
                        a.attr("onclick", "GRecordId=\"" + recordId + "\";chooseTimeBlockStartDate=\"" + time1 + "\";chooseTimeBlockEndDate=\"" + time2 + "\";" + "isWeekdayTimeBlock=1;handleSchedule(null," + prescriptionItemId + "," + patientId + "," + treatmentGroupId + ",\"" + $(td).attr("data-time-block-start") + "\")");
                    }
                }
                $(divTdChild).css("background-color", "#d6eded");
                var divImg2Container = $("<div style='width: 20%;display: inline-block;'>")
                topTag.append(divImg2Container);
            }

            if(isPc()) {
                $(divTdChild).addClass("alt");
                $(divTdChild).append(topTag, a, divBox);
            }
            else {
                $(divTdChild).append(topTag, a);
            }

            $(td).append(divTdChild);
        }
    }

    function getWeekDayTd(time) {
        //debugger;
        var weekday = "";
        var date = getDate(time);
        switch (date.getDay()) {
            case 0:
                weekday = "SUN-";
                break;
            case 1:
                weekday = "MON-";
                break;
            case 2:
                weekday = "TUE-";
                break;
            case 3:
                weekday = "WED-";
                break;
            case 4:
                weekday = "THU-";
                break;
            case 5:
                weekday = "FRI-";
                break;
            case 6:
                weekday = "SAT-";
                break;
            default:
                weekday = null;
                break;
        }

        if (weekday == null) {
            return null;
        }

        var HHMM = date.format("HH:mm");
        var idx = "";
        if (HHMM == "08:00") {
            idx = 1;
        }
        else if (HHMM == "08:35") {
            idx = 2;
        }
        else if (HHMM == "09:10") {
            idx = 3;
        }
        else if (HHMM == "09:45") {
            idx = 4;
        }
        else if (HHMM == "10:20") {
            idx = 5;
        }
        else if (HHMM == "10:55") {
            idx = 6;
        }
        else if (HHMM == "13:00") {
            idx = 7;
        }
        else if (HHMM == "13:35") {
            idx = 8;
        }
        else if (HHMM == "14:10") {
            idx = 9;
        }
        else if (HHMM == "14:45") {
            idx = 10;
        }
        else if (HHMM == "15:20") {
            idx = 11;
        }
        else if (HHMM == "15:55") {
            idx = 12;
        }
        else if (HHMM == "16:30") {
            idx = 13;
        }
        else {
            idx = null;
        }

        if (idx == null) {
            return null;
        }

        return "#" + weekday + idx;
    }

    //option 1:clear ; 2: fill
    function clearOfFillTd(option) {
        var trs = $("#one-week-schedule").children("tbody").children();
        if (trs != null) {
            $.each(trs, function (idxTr, tr) {
                if (idxTr != 0) {
                    var tds = $(tr).children();
                    if (tds != null) {
                        $.each(tds, function (idxTd, td) {
                            if (idxTd != 0 /*&& idx != 1*/) {
                                if (1 == option) {
                                    if (idxTd != 0 /*&& idx != 1*/) {
                                        clearTd(td);
                                    }
                                }
                                else {
                                    if ($(td).children("div").length <= 0) {
                                        tdAddAttr(td)
                                    }
                                }
                            }
                        });
                    }
                }
            });
        }
    }

    function clearTd(e) {
        $(e).attr("onclick", "");
        $(e).attr("data-toggle", "");
        $(e).attr("data-target", "");
        $(e).attr("data-prescription-item-id", "");
        $(e).empty();
    }

    function clearTdAttr(e) {
        $(e).attr("onclick", "");
        $(e).attr("data-toggle", "");
        $(e).attr("data-target", "");
        $(e).attr("data-prescription-item-id", "");
    }

    function tdAddAttr(e) {
        if (new Date() < getDate($(e).attr("data-time-block-end"))) {
            $(e).attr("onclick", "popChoosePatientModal(this)");
            $(e).attr("data-toggle", "modal");
            $(e).attr("data-target", "#modal-choose-patient-div");
            $(e).css("background-color", "white");
        }
        else {
            $(e).css("background-color", "white");
        }
    }

    function filterPatient(option) {
        if (option == 1) {
            var scrollY = $(document).scrollTop();
            currentPage = 1;
            totalPage = 1;
            var id = $("#patient-select").val();
            typeUnderTable = id;
            getPrescriptionItemList(id, new Date().valueOf(), currentPage, pageSize, 1, scrollY);
        }
        else {
//            var time = getDate(chooseTimeBlockStartDate).valueOf();
            var time = new Date().valueOf();

            if ($('#patient-checkbox').is(':checked')) {
                getPrescriptionItemList(2, time, 1, 10000, 2);
            }
            else {
                getPrescriptionItemList(1, time, 1, 10000, 2);
            }
        }
    }

    function popScheduleModal(id) {
        if (0 == $("#" + id).val()) {
            toastr.error("请选择患者");
            return;
        }
        $('#modal-choose-patient-div').modal('hide');
        $('#modal-schedule-div').modal('show');
        isWeekdayTimeBlock = 1;
        handleSchedule(null, prescriptionItemId, patientId, treatmentGroupId, getDate(chooseTimeBlockStartDate));
    }

    function popChoosePatientModal(e) {
        $("#patient-checkbox").prop("checked", false);
        chooseTimeBlockStartDate = $(e).attr("data-time-block-start");
        chooseTimeBlockEndDate = $(e).attr("data-time-block-end");
//        debugger;
        var time = getDate(chooseTimeBlockStartDate).valueOf();
        getPrescriptionItemList(1, time, 1, 10000, 2);
    }

    function changePatient(id) {
//        debugger;
        var obj = $("#" + id + " option:selected");
        prescriptionItemId = obj.attr("data-prescription-item-id");
        treatmentGroupId = obj.attr("data-group-id");
        patientId = obj.attr("data-patient-id");
        residueTimes = obj.attr("data-residue-times");
    }

    function del(id) {
        mandy_delete_treatment_record(id, function () {
            getTherapistSchedulePeriods();
            getPrescriptionItemList(typeUnderTable, new Date().valueOf(), currentPage, pageSize, 1);
            toastr.success("删除成功！");
        });
    }

    function designatedPage(e) {
        var ev = window.event || e;
        var pageNum = $("#page-num").val();
        ;
        if (ev.keyCode == 13) {
            if (!/^[0-9]*$/.test(pageNum) || pageNum > totalPage || pageNum < 1) {
                toastr.error("请输入正确的页数!");
                return;
            }
        }
    }

    function search() {
        var scrollY = $(document).scrollTop();
        currentPage = 1;
        getPrescriptionItemList(typeUnderTable, new Date().valueOf(), currentPage, pageSize, 3, scrollY);
    }

    (function ($) {
        $.fn.hoverDelay = function (options) {
            var defaults = {
                hoverDuring: 500,
                outDuring: 500,
                hoverEvent: function () {
                    $.noop();
                },
                outEvent: function () {
                    $.noop();
                }
            };
            var sets = $.extend(defaults, options || {});
            var hoverTimer, outTimer;
            return $(this).each(function () {
                $(this).hover(function () {
                    clearTimeout(outTimer);
                    hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
                }, function () {
                    clearTimeout(hoverTimer);
                    outTimer = setTimeout(sets.outEvent, sets.outDuring);
                });
            });
        }
    })(jQuery);


</script>

</body>


</html>